Public Class StoolExamResultParasiteHistory

    Protected _year As String
    Protected _police As New Police()
    Protected _parasite As New Parasite()
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property year() As String
        Get
            Return _year
        End Get
        Set(ByVal value As String)
            _year = value
        End Set
    End Property

    Public Property police() As Police
        Get
            Return _police
        End Get
        Set(ByVal value As Police)
            _police = value
        End Set
    End Property

    Public Property parasite() As Parasite
        Get
            Return _parasite
        End Get
        Set(ByVal value As Parasite)
            _parasite = value
        End Set
    End Property

    Public Function getPoliceStoolExamResultParasiteHistory(ByVal inYear As String, ByVal inCitizenID As String) As DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PoliceStoolExamResultParasite"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", inCitizenID)
        objCmd.Parameters.Add(objParam)

        objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "PoliceStoolExamParasite")

        Return objDs
    End Function

    Protected Function getsPoliceStoolExamResultParasiteHistory(ByVal inYear As String, ByVal inCitizenID As String) As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_PoliceStoolExamResultParasite"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", inCitizenID)
        objCmd.Parameters.Add(objParam)

        objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", inYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "PoliceStoolExamParasite")

        For Each objDr As System.Data.DataRow In objDs.Tables("PoliceStoolExamParasite").Rows
            Dim obj As StoolExamResultParasiteHistory = New StoolExamResultParasiteHistory
            obj.year = Utilities.ClearDBNullToMinValue(objDr.Item("year"), TypeCode.String)
            obj.police.citizen_id = Utilities.ClearDBNullToMinValue(objDr.Item("citizen_id"), TypeCode.String)
            obj.parasite.parasite_id = Utilities.ClearDBNullToMinValue(objDr.Item("parasite_id"), TypeCode.Int32)
            obj.police.organization.organization_id = Utilities.ClearDBNullToMinValue(objDr.Item("organization_id"), TypeCode.String)
            obj.police.organization.organization_name_tha = _
                Utilities.ClearDBNullToMinValue(objDr.Item("organization_name_tha"), TypeCode.String)
            obj.parasite.parasite_name_tha = _
                Utilities.ClearDBNullToMinValue(objDr.Item("parasite_name_tha"), TypeCode.String)
            obj.parasite.parasite_name_eng = _
                Utilities.ClearDBNullToMinValue(objDr.Item("parasite_name_eng"), TypeCode.String)
            obj.police.create_user = Utilities.ClearDBNullToMinValue(objDr.Item("create_user"), TypeCode.String)
            obj.police.create_date = Utilities.ClearDBNullToMinValue(objDr.Item("create_date"), TypeCode.DateTime)

            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Sub LoadPoliceStoolExamResultParasiteHistory(ByVal inYear As String, ByVal inCitizenID As String)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsPoliceStoolExamResultParasiteHistory(inYear, inCitizenID)
    End Sub

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _year = _Data(_DataCurrent).year
            _police.citizen_id = _Data(_DataCurrent).police.citizen_id
            _parasite.parasite_id = _Data(_DataCurrent).parasite.parasite_id
            _parasite.parasite_name_tha = _Data(_DataCurrent).parasite.parasite_name_tha
            _parasite.parasite_name_eng = _Data(_DataCurrent).parasite.parasite_name_eng
            _police.organization.organization_id = _Data(_DataCurrent).police.organization.organization_id
            _police.organization.organization_name_tha = _Data(_DataCurrent).police.organization.organization_name_tha
            _police.create_user = _Data(_DataCurrent).police.create_user
            _police.create_date = _Data(_DataCurrent).police.create_date
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Sub deletePoliceStoolExamResultParasiteHistory(ByVal inPoliceStoolExamResultParasiteHistory _
    As StoolExamResultParasiteHistory)
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_DELETE_PoliceStoolExamResultParasite"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", _
                Utilities.SendToDatabase(Utilities.ConvertCitizenID(inPoliceStoolExamResultParasiteHistory.police.citizen_id)))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", _
                Utilities.SendToDatabase(inPoliceStoolExamResultParasiteHistory.year))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Function insertPoliceStoolExamResultParasiteHistory(ByVal inPoliceStoolExamResultParasiteHistory _
    As StoolExamResultParasiteHistory) As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_PoliceStoolExamResultParasiteHistory"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inCitizenID", _
                Utilities.SendToDatabase(Utilities.ConvertCitizenID(inPoliceStoolExamResultParasiteHistory.police.citizen_id)))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inYear", _
                Utilities.SendToDatabase(inPoliceStoolExamResultParasiteHistory.year))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inParasiteID", _
                Utilities.SendToDatabase(inPoliceStoolExamResultParasiteHistory.parasite.parasite_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", _
                Utilities.SendToDatabase(inPoliceStoolExamResultParasiteHistory.police.organization.organization_id))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationNameTha", _
                Utilities.SendToDatabase(inPoliceStoolExamResultParasiteHistory.police.organization.organization_name_tha))
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inCreateUser", _
                Utilities.SendToDatabase(inPoliceStoolExamResultParasiteHistory.police.create_user))
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

End Class
